﻿using Maticsoft.DBUtility;
using System;
using System.Collections.Generic;
using System.Data.OracleClient;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using Xiaov.SmartWeb.Infrastructure.ExtMethod;
using Xiaov.SmartWeb.Model.Statistical;

namespace Xiaov.SmartWeb.Application.PluginSrc.StatisticalSystem
{
    public partial class SaveData : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string xml = Request.Form["data"].ToRequestString();
            //string xml = "%3CDataRoot%3E%3CRecord%3E%3CNF%3E2010%3C%2FNF%3E%3CYF%3E9%3C%2FYF%3E%3CZBBM%3ESC220010%3C%2FZBBM%3E%3CDWBM%3EXB12%3C%2FDWBM%3E%3CZBMC%3E%C2%A0%C2%A0%C2%A0%EF%BC%882%EF%BC%89%E6%B3%A8%E6%B0%B4%3C%2FZBMC%3E%3CZBDM%3E%3C%2FZBDM%3E%3CCJ%3E4%3C%2FCJ%3E%3CHC%3E10%3C%2FHC%3E%3CJLDW%3E%E4%B8%87%E5%90%A8%3C%2FJLDW%3E%3CNJH%3E%3C%2FNJH%3E%3CBYSJ%3E2%3C%2FBYSJ%3E%3CBNLJ%3E%3C%2FBNLJ%3E%3CQNTQLJ%3E0%3C%2FQNTQLJ%3E%3CBZ%3E%3C%2FBZ%3E%3CLBBM%3ESC220010%3C%2FLBBM%3E%3CROWID%3EAAAmKmAAQAAACipABH%3C%2FROWID%3E%3C%2FRecord%3E%3CRecord%3E%3CNF%3E2010%3C%2FNF%3E%3CYF%3E9%3C%2FYF%3E%3CZBBM%3ESC220011%3C%2FZBBM%3E%3CDWBM%3EXB12%3C%2FDWBM%3E%3CZBMC%3E%C2%A0%C2%A0%C2%A0%EF%BC%883%EF%BC%89%E6%B2%B9%E6%B0%94%E8%BF%90%E8%BE%93%3C%2FZBMC%3E%3CZBDM%3E%3C%2FZBDM%3E%3CCJ%3E4%3C%2FCJ%3E%3CHC%3E11%3C%2FHC%3E%3CJLDW%3E%E4%B8%87%E5%90%A8%3C%2FJLDW%3E%3CNJH%3E%3C%2FNJH%3E%3CBYSJ%3E2%3C%2FBYSJ%3E%3CBNLJ%3E%3C%2FBNLJ%3E%3CQNTQLJ%3E0%3C%2FQNTQLJ%3E%3CBZ%3E%3C%2FBZ%3E%3CLBBM%3ESC220011%3C%2FLBBM%3E%3CROWID%3EAAAmKmAAQAAACipABI%3C%2FROWID%3E%3C%2FRecord%3E%3C%2FDataRoot%3E";
            string table = Request.Form["tn"].ToRequestString();
            string year = Request.Form["year"].ToRequestString();
            string month = Request.Form["month"].ToRequestString();
            string dwbm = Request.Form["dwbm"].ToRequestString();
            string zd = Request.Form["zd"].ToRequestString();
            string zbbm = Request.Form["zbbm"].ToRequestString();

            xml = Server.UrlDecode(xml);

            GridData gd = new GridData();
            //if (table == ("NH68") || table == ("NH68_ALL"))
            //    gd.SaveNH68(table, xml, dwbm, year, month);
            //else
            //    if (table == "TG85")
            //        gd.SaveTG85(table, xml, dwbm, year, month);
            //else
            gd.Save(table, xml);
            //调用陈君的计算过程
            //LoadProc("p_calculete", table,  year, month,dwbm);
            
        }

        /// <summary>
        /// 调用存储过程
        /// </summary>
        /// <param name="ProcdureName">过程名称</param>
        /// <returns>返回值</returns>
        public bool LoadProc(string ProcdureName,string TableName ,string Year,string Month,string DWBM)
        {
            OracleParameter[] parameters ={
            new OracleParameter("v_bbbm",OracleType.VarChar,20),
　　     new OracleParameter("v_dwbm",OracleType.VarChar,20),
　　     new OracleParameter("v_nf",OracleType.Number,4),
            new OracleParameter("v_yf",OracleType.Number,2),
　　      };
            parameters[0].Value = TableName.ToUpper();
            parameters[1].Value = DWBM.ToUpper();
            parameters[2].Value = Year;
            parameters[3].Value = Month;
            try
            {
                OracleDataReader odr = Maticsoft.DBUtility.DbHelperOra.RunProcedure(ProcdureName, parameters);
                odr.Close();
                return true;
            }
            catch
            {
                return false;
            }
        }
    }
}